package com.kongyz.flowable;


/**
 * @Author: KongYz On 2022-3-31.
 * @Description: 流程链
 */
public abstract class AbstractFlowChain {

    /**
     * 下个节点
     */
    protected AbstractFlowChain nextFlowChain;
    /**
     * 当前链
     */
    protected FlowChainEnum currentChain;

    private void setNextFlowChain(AbstractFlowChain nextFlowChain) {
        this.nextFlowChain = nextFlowChain;
    }

    /**
     * 设置当前流程链
     */
    abstract protected FlowChainEnum getCurrentChain();

    /**
     * 创建下一个流程节点
     *
     * @param nextChain
     * @param args
     */
    public void notifyChanged(FlowChainEnum nextChain, String args) {
        //当前节点小于下一个节点时再执行
        if (getCurrentChain().getIndex() <= nextChain.getIndex()) {
            doNotifyChanged(args);
            return;
        }
        //往下流转
        if(nextFlowChain!=null){
            nextFlowChain.doNotifyChanged(args);
        }
    }

    /**
     * 执行具体的下个节点通知
     * @param args
     */
    abstract protected void doNotifyChanged(String args);


    public static  AbstractFlowChain getChain(){
        AbstractFlowChain flowChain=new ProjectPlanFlowChain();
        flowChain.setNextFlowChain(new ProjectFlowChain());
        flowChain.setNextFlowChain(new projectBuyagencyFlowChain());
        return flowChain;
    }
}
